< previous page page_359 next page >

Page 359
Tutorial 7
Classes, Structures, and User-Defined Types
From the viewpoint of a Visual Basic programmer, there is no difference between C language classes, structs, and Visual Basic user-defined types. They all represent a way to group variables together in memory so they can be handled as a unita single structure in memory. Many Win32 API functions take structures as parameters. The individual variables within a structure are sometimes called the "fields" of the structure.
The C language is able to pass structures by value, in which case all of the structure data is placed on the stack. Visual Basic is not able to pass structures by value, but fortunately this will rarely be a problem. Most Win32 API functions expect structures to be passed by reference. In other words, they expect to see a pointer to a structure as a stack parameter.
The one case where a structure is passed by value under Win32 is the POINT structure.
Handling Points
The POINT structure is defined in C and Visual Basic as follows:
C/C++VISUAL BASIC
typedef struct tagPOINT
{
    LONG  x;
    LONG  y;
} POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT
Type POINTAPI
        x As Long
        y As Long
End Type

You will notice that the Visual Basic structure is not called POINT. This is necessary because "Point" is a Visual Basic reserved word. An error occurs if you try to create a user-defined type with the same name as a reserved word.

 
< previous page page_359 next page >